package com.example.demo.lambda;

import java.io.File;
import java.util.List;
import java.util.Objects;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * @Author xiao
 * @Date 2025/4/29 上午 8:56
 * @ClassName: Practice
 * @Desc:
 */
public class Practice {

    public static void main(String[] args) {

    }

    Function<String, Integer> lambda = (String s) -> Integer.parseInt(s);
    Function<String, Integer> newLambda = Integer::parseInt;

    BiPredicate<List<String>, String> lambda2 = (list, element) -> list.contains(element);
    BiPredicate<List<String>, String> newLambda2 = List::contains;



    BiPredicate<Student, Object> lambda3 = (stu, obj) -> stu.equals(obj);
    BiPredicate<Student, Object> newLambda3 = Student::equals;



    Predicate<File> lambda4 = (file) -> file.exists();
    Predicate<File> newLambda4 = File::exists;

    Runtime runtime = Runtime.getRuntime();
    Supplier<Long> lambda5 = () -> runtime.freeMemory();
    Supplier<Long> newLambda5 = runtime::freeMemory;

    static class Student{
        private String name;
        private Integer age;

        public Student() {
        }

        public Student(String name, Integer age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public Integer getAge() {
            return age;
        }

        @Override
        public boolean equals(Object o) {
            if (o == null || getClass() != o.getClass()) return false;
            Student student = (Student) o;
            return Objects.equals(name, student.name) && Objects.equals(age, student.age);
        }

        @Override
        public int hashCode() {
            return Objects.hash(name, age);
        }
    }

}
